package com.pansoft.openplanet.adapter;

import android.app.Activity;
import android.view.MotionEvent;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.efounder.view.CommonSwipeMenuLayout;
import com.pansoft.hd.model.BtcHdWallet;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.widget.PassWordAlertDialog;

import java.util.List;

/**
 * 钱包地址列表的适配器
 */
public class AssetWalletAddressListAdapter extends BaseQuickAdapter<BtcHdWallet.BtcChildAddress, BaseViewHolder> {

    public AssetWalletAddressListAdapter(List<BtcHdWallet.BtcChildAddress> data) {
        super(R.layout.asset_item_wallet_address_layout,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BtcHdWallet.BtcChildAddress item) {
        helper.setText(R.id.tv_wallet_address,item.getAddress());
        helper.setText(R.id.tv_xpub,"xpub 0/"+item.getIndex());
        if(item.isSelected()){
            helper.setGone(R.id.iv_check,true);
        }else {
            helper.setGone(R.id.iv_check,false);
        }
        final CommonSwipeMenuLayout sml_swipe = helper.getView(R.id.sml_swipe);
        sml_swipe.setSwipeEnable(false);
        sml_swipe.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() == MotionEvent.ACTION_UP){
                   sml_swipe.smoothClose();
                    PassWordAlertDialog dialog = new PassWordAlertDialog((Activity) mContext,
                            new PassWordAlertDialog.OnEnterClick() {
                                @Override
                                public void passVerifySuccess(String passWord) {

                                }
                            });
                    dialog.show();
                }
                return false;
            }
        });

        helper.addOnClickListener(R.id.rl_root);
    }

}
